﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Servlet
{
    public class Controler : CnGine.HttpHander.Base
    {
        private List<DemoModel> listDM = new List<DemoModel>();
        public override void Execute()
        {
            string ss = "";

            StringBuilder sb = new StringBuilder();
            for (int i = 1; i < 21; i++)
            {
                DemoModel dm = new DemoModel();
                dm.Code = i.ToString("000");
                dm.Name = "name" + i.ToString();
                dm.Addr = "addr" + i.ToString();
                dm.Col4 = "cooooooool" + i.ToString() + DateTime.Now.ToString();
                listDM.Add(dm);
            }

            Context.Items.Add("datas", listDM);
            Server.Transfer("/default2.aspx");
            Delete();
            sb.AppendFormat("\"total\":{0},\"rows\":{1}", listDM.Count * 5, CnGine.Json.JavaScriptConvert.SerializeObject(listDM));
            Response.Write("{" + sb.ToString() + "}");
        }

        public void Delete()
        {
            //string[] ids = base.FormString("ids").Split(',');
            string[] ids = new string[] { "001", "002" };
            foreach (string s in ids)
            {
                DemoModel d = listDM.Find(delegate(DemoModel dd) { return dd.Code == s; });
                if (d != null)
                {
                    listDM.Remove(d);
                }
            }
        }
    }
    public class DemoModel
    {
        private string _code = "";
        private string _name = "";
        private string _addr = "";
        private string _col4 = "";

        public string Code
        {
            set { this._code = value; }
            get { return this._code; }
        }
        public string Name
        {
            set { this._name = value; }
            get { return this._name; }
        }
        public string Addr
        {
            set { this._addr = value; }
            get { return this._addr; }
        }
        public string Col4
        {
            set { this._col4 = value; }
            get { return this._col4; }
        }
    }

}
